package cn.tedu.spring.diautowired;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Author：程Sir
 * Name： SpringTest01
 * Content:
 */
public class DITest {
    AnnotationConfigApplicationContext acac;
    @Test
    public void test(){
        // 2. 获取容器中的指定对象
        Worker worker = acac.getBean(Worker.class);
        worker.work();
    }

    @Test
    public void test1(){
        // 2. 获取容器中的指定对象
        WorkerResource worker = acac.getBean(WorkerResource.class);
        worker.work();
    }
    @Before
    public void init(){
        // 1.实例化spring容器
        acac = new AnnotationConfigApplicationContext(SpringConfig.class);
        System.out.println("spring容器初始化....");

    }
    @After
    public void destory(){
        acac.close();
    }
}
